﻿<?xml version="1.0" encoding="utf-8"?><Articles><Article><ArticlesID>574</ArticlesID><Title>Truy vấn một bản ghi ngẫu nhi&amp;#234;n với SQL</Title><Body>&amp;lt;p&amp;gt;Với MySQL:&amp;lt;/p&amp;gt;
&amp;lt;pre class=&amp;quot;brush: sql;&amp;quot; title=&amp;quot;code&amp;quot;&amp;gt;
SELECT column FROM table
ORDER BY RAND()
LIMIT 1&amp;lt;/pre&amp;gt;
&amp;lt;p&amp;gt;&amp;lt;br /&amp;gt;
Với PostgreSQL:&amp;lt;/p&amp;gt;
&amp;lt;pre class=&amp;quot;brush: sql;&amp;quot; title=&amp;quot;code&amp;quot;&amp;gt;
SELECT column FROM table
ORDER BY RANDOM()
LIMIT 1&amp;lt;/pre&amp;gt;
&amp;lt;p&amp;gt;Với Microsoft SQL Server:&amp;lt;/p&amp;gt;
&amp;lt;pre class=&amp;quot;brush: sql;&amp;quot; title=&amp;quot;code&amp;quot;&amp;gt;
SELECT TOP 1 column FROM table
ORDER BY NEWID()&amp;lt;/pre&amp;gt;
&amp;lt;p&amp;gt;Với IBM DB2&amp;lt;/p&amp;gt;
&amp;lt;pre class=&amp;quot;brush: sql;&amp;quot; title=&amp;quot;code&amp;quot;&amp;gt;
SELECT column, RAND() as IDX
FROM table
ORDER BY IDX FETCH FIRST 1 ROWS ONLY&amp;lt;/pre&amp;gt;
&amp;lt;p&amp;gt;Với Oracle:&amp;lt;/p&amp;gt;
&amp;lt;pre class=&amp;quot;brush: sql;&amp;quot; title=&amp;quot;code&amp;quot;&amp;gt;
SELECT column FROM
( SELECT column FROM table
ORDER BY dbms_random.value )
WHERE rownum = 1
&amp;lt;/pre&amp;gt;</Body><CommentEnabled>True</CommentEnabled><ViewCount>0</ViewCount><ReleaseDate>11/1/2009 12:13:34 AM</ReleaseDate><TotalComment>0</TotalComment><IsMedia>False</IsMedia><IsPicture>False</IsPicture><IsVote>True</IsVote><ArticlePassword /><PostVisible>0</PostVisible><ArticlePath>/2009/11/1/Truy-van-mot-ban-ghi-ngau-nhien-voi-SQL-23E</ArticlePath><Approved>True</Approved><ImagePath /><CategoryId>35</CategoryId><ArrayCatID>35|25</ArrayCatID></Article></Articles>